# -*- coding: utf-8 -*-
# @Time     : 2021/12/1 14:07
# @Author   : wljess
# @File     : Thread中的其他方式.py
# @Describe : 
# @Software : PyCharm

import time
from threading import Thread, current_thread, enumerate, active_count

print(Thread)
print(dir(Thread))
print(Thread.__dict__)


def task(num):
    time.sleep(0.5)
    print(f"i am son{num} thread...")


for i in range(3):
    t = Thread(target=task, args=(i,))
    t.start()
    print("获取线程的名字：", t.getName())
    print("判断线程是否活着", t.is_alive())
    print("判断线程是否是守护线程：", t.isDaemon())
    print("获取线程id：", t.ident)

print("获取主线程id:", current_thread().ident)
print("获取主线程名字：", current_thread().getName())
print("判断子线程是否为守护线程：", current_thread().isDaemon())
print("判断当前有哪些线程活着：", enumerate())
print("判断当前运行的线程数量：", active_count())
print("判断当前运行的线程数量：", len(enumerate()))
